package com.baaio.conn;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;

import com.baaio.conn.Interface.BaaioConn;
import com.baaio.reflect.BaaioReflect;
import com.baaio.util.SetOtherDBName;

/**
 * 主要接口，提供增，删，查，改。等方法<br>
 * 该类不可以new，需要调用getInstance()方法获得实例。 这个是单例模式。<br>
 * 获得实例后，你可以任意多次调用该类提供的方法。<br>
 * 
 * 
 */
public class BaaioConnImpl implements BaaioConn {

	@Override
	public boolean clearTableTruncate(String tableName) {
		// TODO Auto-generated method stub
		return getConn().clearTableTruncate(tableName);
	}

	private SetOtherDBName otherDBName;
	private static ArrayList<BaaioConn> bcilist = new ArrayList<BaaioConn>();

	public BaaioConnImpl() {
		otherDBName = new SetOtherDBName("");
	}

	public BaaioConnImpl(String DBName) {
		otherDBName = new SetOtherDBName(DBName);
	}

	private BaaioConn getConn() {

		BaaioConn bconn = null;
		if (otherDBName.getDBName().equals("")
				|| otherDBName.getDBName() == null) {
			bconn = new BaaioProxy().getBaaioConn();
			bcilist.add(bconn);
		} else {
			bconn = new BaaioProxy().getBaaioConn(otherDBName.getDBName());
			bcilist.add(bconn);
		}
		return bconn;
	}

	@Override
	public ResultSet queryData(String tabelname, ArrayList<String> list,
			String condiction) {

		return getConn().queryData(tabelname, list, condiction);
	}

	@Override
	public ResultSet queryData(String tableName, String fields,
			String condiction) {

		return getConn().queryData(tableName, fields, condiction);
	}

	@Override
	public boolean saveData(String tableName, HashMap<String, String> map) {
		return getConn().saveData(tableName, map);

	}

	@Override
	public boolean saveData(Object object) {

		return getConn().saveData(object);

	}

	@Override
	public boolean removeData(String tableName, String condition) {

		return getConn().removeData(tableName, condition);
	}

	@Override
	public boolean removeData(String tableName, String cName,
			ArrayList<String> list) {

		return getConn().removeData(tableName, cName, list);
	}

	@Override
	public boolean removeData(String tableName, String dcName, String condiction) {

		return getConn().removeData(tableName, dcName, condiction);
	}

	@Override
	public boolean updateData(String table, HashMap<String, String> map,
			String upCondition) {

		return getConn().updateData(table, map, upCondition);
	}

	@Override
	public boolean updateData(Object object, Object upConditionObject) {

		BaaioReflect br = new BaaioReflect();
		return getConn()
				.updateData(br.getTableName(object), br.getValue(object),
						br.getUpConditionString(upConditionObject));

	}

	@Override
	public ResultSet query(String sql) {
		return getConn().query(sql);
	}

	@Override
	public void close() {

		getConn().close();

	}

	@Override
	public boolean removeData(Object object, String value) {

		return getConn().removeData(object, value);

	}

	@Override
	public ResultSet queryX(String tableName) {

		return getConn().queryX(tableName);
	}

	@Override
	public ResultSet queryData(Object object, String value) {

		return getConn().queryData(object, value);
	}

	@Override
	public ResultSet lift(Object A, Object B) {

		return getConn().lift(A, B);
	}

	@Override
	public boolean hasData(String tabelName, String item, String value) {

		return getConn().hasData(tabelName, item, value);
	}

	@Override
	public Object queryDataB(Object object, String value) {
		// TODO Auto-generated method stub

		

		return getConn().queryDataB(object, value);
	}

	@Override
	public Object queryDataA(Object object) {
		// TODO Auto-generated method stub
		return getConn().queryDataA(object);
	}

	@Override
	public boolean hasData(Object object) {
		// TODO Auto-generated method stub
		return getConn().hasData(object);
	}

}
